import axios, { AxiosResponse, AxiosRequestConfig,AxiosError,AxiosInstance } from "axios";
const { VITE_API_URL } = process.env;
const request: AxiosInstance = axios.create({
  baseURL: VITE_API_URL,
  timeout: 20 * 1000
});
// 请求拦截器
request.interceptors.request.use((config: AxiosRequestConfig) => {
  if (config.headers) {
    config.headers.token = sessionStorage.getItem('token') || ''
  } 
  return config
},(error:AxiosError)=>{
  return Promise.reject(error)
});
// 响应拦截器
request.interceptors.response.use( (response:AxiosResponse) =>{
  return response.data
},(error:AxiosError) => {
  return Promise.reject(error)
})
export default request;